﻿using Autofac.Core;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Application.Command.SheepManagementCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 栋舍管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BuildingManagementController : ControllerBase
    {
        private readonly IMediator _mediator;
        IBuildingManagementService service;
     

        public BuildingManagementController(IMediator mediator, IBuildingManagementService service)
        {
            _mediator = mediator;
            this.service = service;
           
        }

        /// <summary>
        /// 栋舍添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> Create([FromForm]BuildingManagementCreateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        ///栋舍显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Results<PageOutput<BuildingManagement>>> GetSheepManagement(BuildingManagementListCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 栋舍删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DelBuildingManagement(BuildingManagementDelCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 栋舍反填
        /// </summary>
        /// <param name="buildingManagementId"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<Results<BuildingManagement>> GetFtBuildingManagement(int buildingManagementId)
        {
            return Results<BuildingManagement>.DataResult(service.GetFtBuildingManagement(buildingManagementId));
        }

        /// <summary>
        /// 修改栋舍
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Results<int>> Update(BuildingManagementUpdaCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 批量删除栋舍
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DelRangeBuildingManagement(BuildingManagementDelRangeCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
